Skip to content

fix: only redirect a failed SAML sign-in to a redirect_uri registered… - #4147

Open
fhanik wants to merge 2 commits into
developfrom
pr/saml-failure-redirect-uri
Open

fhanik wants to merge 2 commits into
developfrom
pr/saml-failure-redirect-uri

Conversation

@fhanik

@fhanik fhanik commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

… for the client

When a SAML sign-in fails during an authorization request, the failure handler sends the browser back to the redirect_uri of the saved /oauth/authorize request, with error=access_denied and the error description. The saved request holds the query string as it was received, before the redirect_uri was compared with the client's registered values.

The handler now loads the client named in the saved request and resolves the redirect_uri with the same RedirectResolver that /oauth/authorize uses. A registered redirect_uri is used as before. When the client is unknown, the request has no client_id, or the redirect_uri does not match the client, nothing is redirected and the user sees the /saml_error page.

The error and error_description sent to a registered redirect_uri are unchanged.

… for the client

When a SAML sign-in fails during an authorization request, the failure
handler sends the browser back to the redirect_uri of the saved
/oauth/authorize request, with error=access_denied and the error
description. The saved request holds the query string as it was received,
before the redirect_uri was compared with the client's registered values.

The handler now loads the client named in the saved request and resolves
the redirect_uri with the same RedirectResolver that /oauth/authorize
uses. A registered redirect_uri is used as before. When the client is
unknown, the request has no client_id, or the redirect_uri does not match
the client, nothing is redirected and the user sees the /saml_error page.

The error and error_description sent to a registered redirect_uri are
unchanged.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An active moderate issue remains because malformed saved redirect URIs can throw an uncaught exception during failed SAML sign-in, causing a server error instead of the intended fallback.

1 open issue
What changed in this PR

This PR stops a failed SAML sign-in from sending the browser to any redirect_uri in the saved /oauth/authorize request. The handler now loads the client named in that request and checks the redirect_uri with the same RedirectResolver that /oauth/authorize uses. If the client is unknown, the client_id is missing, or the redirect_uri is not registered, the user sees /saml_error. The error and error_description parameters sent to a registered URI are unchanged.

Changes:

  • SamlLoginAuthenticationFailureHandler takes the redirect resolver, client services, and zone manager as constructor arguments. It only redirects after the redirect_uri resolves for the client.
  • SamlAuthenticationFilterConfig wires those beans into the failure handler bean.
  • Unit, zone-path, MockMvc, and integration tests cover registered, unregistered, unknown-client, and missing-client_id cases.
File Description
uaa/​src/​test/​java/​org/​cloudfoundry/​identity/​uaa/​mock/​saml/​SamlAuthenticationMockMvcTests.java Adds MockMvc tests for a failed SAML sign-in with a registered and an unregistered redirect_uri.
uaa/​src/​test/​java/​org/​cloudfoundry/​identity/​uaa/​integration/​feature/​SamlFailureRedirectIT.java New integration test that checks the browser lands on /saml_error or the registered redirect after a failed sign-in.
server/​src/​test/​java/​org/​cloudfoundry/​identity/​uaa/​provider/​saml/​SamlLoginAuthenticationFailureHandlerZonePathTest.java Updates existing tests for the new constructor and adds cases for unregistered and unknown clients across zone path modes.
server/​src/​test/​java/​org/​cloudfoundry/​identity/​uaa/​provider/​saml/​SamlLoginAuthenticationFailureHandlerTest.java Updates existing tests for the new constructor and adds cases for unregistered, unknown, and missing client_id requests.
server/​src/​main/​java/​org/​cloudfoundry/​identity/​uaa/​provider/​saml/​SamlLoginAuthenticationFailureHandler.java Resolves the saved redirect_uri against the client's registered URIs and falls back to /saml_error when it does not match.
server/​src/​main/​java/​org/​cloudfoundry/​identity/​uaa/​provider/​saml/​SamlAuthenticationFilterConfig.java Passes the resolver, client services, and zone manager into the failure handler bean.

Review effort: Lite

@github-project-automation github-project-automation Bot moved this from Inbox to Pending Merge | Prioritized in Foundational Infrastructure Working Group Nov 12, 2026
@strehle
strehle requested a review from duanemay November 13, 2026 06:19

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Pending Merge | Prioritized

Development

Successfully merging this pull request may close these issues.

3 participants